// Matthew Firtion
// HW1: ActionScript
// MET CS 701 Fall 2011 OL
// Boston University

package
{
	import flash.display.Sprite;
	
	public class HW1_firtion extends Sprite
	{
		public function HW1_firtion()
		{
			// Initialize XML document
			var courseList:XML = 
				<courses>
					<dept id='MET CS'>
						<name>Metropolitan College Computer Science</name>
						<course id='MET CS341'>
							<name>Data Structures</name>
							<instructor>Maslanka</instructor>
							<day>Wednesday</day>
						</course>
						<!-- ... -->
						<course id='MET CS701'>
							<name>Advanced Web Application Development</name>
							<instructor>Kalathur</instructor>
							<day>Tuesday</day>
						</course>
					</dept>
						<!-- ... -->
					<dept id='CAS CS'>
						<name>College of Arts and Sciences Computer Science</name>
						<course id='CAS CS105'>
							<name>Databases</name>
							<instructor>Sullivan</instructor>
							<day>Monday</day>
						</course>
						<!-- ... -->
						<course id='CAS CS455'>
							<name>Computer Networks</name>
							<instructor>Crovella</instructor>
							<day>Thursday</day>
						</course>
					</dept>
				</courses>
				
				// Display ids and names of all departments
				trace("Dept Ids and Names");
				var selectedList:XMLList =
					courseList.dept;
				
				var depts:Array = new Array();
				
				var deptLoopCount:int = 0;
				
				// Loop through depts
				for each (var entry:XML in selectedList) {
					trace(entry.@id + ", " + entry.name);
					depts[deptLoopCount] = entry.@id;
					deptLoopCount++;
				}
				trace("---------------------------");
				
				// Loop through departments array
				for(var i:int = 0; i < depts.length; ++i) {
					trace("Offerings from " + depts[i]);
					
					// Get all courses in the current dept
					var subCourse:XMLList = 
						courseList.dept.(@id == depts[i]).course;
					
					// Loop through courses for the current dept and print
					for each (var entry2:XML in subCourse) {
						trace(entry2.@id + " (" + entry2.name + ") by Prof. " +
							entry2.instructor + " on " + entry2.day);
					}
					trace("---------------------------");
					
					
					
				}
		}
	}
}